/**
 * 
 */
package com.tvshows.front.view.favorite;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;

import com.tvshows.front.ui.favorite.FavoriteUI;
import com.tvshows.front.ui.favorite.ListCompositeFavoriteUI;
import com.tvshows.front.ui.favorite.UpsideCompositeFavoriteUI;

/**
 * @author tMidy
 * <p>
 * Favorite Panel : contains the list of the favorite shows and allows actions on it
 * </p>
 */
public class FavoriteView
    extends Composite
    implements FavoriteUI
{

    /**
     * form data measure
     */
    private static final Integer DATA_HUNDRED = 100;

    /**
     * form data measure
     */
    private static final Integer DATA_TWENTY = 20;

    /**
     * The sashData for the buttons
     */
    private FormData buttonGroupData;

    /**
     * The sash data for the list
     */
    private FormData listData;

    /**
     * The {@link UpsideCompositeFavoriteUI}
     */
    private UpsideCompositeFavoriteView upsideComposite;

    /**
     * The {@link ListCompositeFavoriteUI}
     */
    private ListCompositeFavoriteView listComposite;

    /**
     * Constructor of the class
     */
    public FavoriteView( Shell shell, int style )
    {
        super( shell, style );
        this.setLayout( new FormLayout() );
        this.initFormData();
        this.initComposites();
    }

    /**
     * Initializes the layout of the frame
     */
    public void initFormData()
    {
        /*
         * The sash
         */
        Sash favoriteSash = new Sash( this, SWT.HORIZONTAL );
        /*
         * The sashData for the sash
         */
        FormData sashData = new FormData();
        sashData.left = new FormAttachment( 0, 0 );
        sashData.bottom = new FormAttachment( DATA_TWENTY, 0 );
        sashData.right = new FormAttachment( DATA_HUNDRED, 0 );

        buttonGroupData = new FormData();
        buttonGroupData.left = new FormAttachment( 0, 0 );
        buttonGroupData.right = new FormAttachment( DATA_HUNDRED, 0 );
        buttonGroupData.top = new FormAttachment( 0, 0 );
        buttonGroupData.bottom = new FormAttachment( favoriteSash, 0 );

        listData = new FormData();
        listData.left = new FormAttachment( 0, 0 );
        listData.right = new FormAttachment( DATA_HUNDRED, 0 );
        listData.top = new FormAttachment( favoriteSash, 0 );
        listData.bottom = new FormAttachment( DATA_HUNDRED, 0 );

        favoriteSash.setLayoutData( sashData );

    }

    /**
     * Initializes the composites
     */
    public void initComposites()
    {
        upsideComposite = new UpsideCompositeFavoriteView( this, SWT.BORDER );
        upsideComposite.setLayoutData( buttonGroupData );
        upsideComposite.setToolTipText( "upsdide" );
        listComposite = new ListCompositeFavoriteView( this, SWT.BORDER );
        listComposite.setLayoutData( listData );

        this.layout();
        this.update();
    }

    /**
     * @see com.tvshows.front.ui.favorite.FavoriteUI#setLayoutData(org.eclipse.swt.layout.FormData)
     */
    public void setLayoutData( FormData favorisData )
    {
        super.setLayoutData( favorisData );
    }

    /**
     * @see com.tvshows.front.ui.favorite.FavoriteUI#getUpsideCompositeFavoriteUI()
     */
    @Override
    public UpsideCompositeFavoriteUI getUpsideCompositeFavoriteUI()
    {
        return upsideComposite;
    }

    /**
     * @see com.tvshows.front.ui.favorite.FavoriteUI#getListCompositeFavoriteUI()
     */
    @Override
    public ListCompositeFavoriteUI getListCompositeFavoriteUI()
    {
        return listComposite;
    }

}
